package configuration.options;

import java.util.ArrayList;

import configuration.parameters.DoubleValuedParameter;
import configuration.parameters.Parameter;

import database.mediator.MediatorInterface;
import distributedRE.model.DistributedREModel;
import distributedRE.model.Document;
import distributedRE.model.QueryDatabase;
import distributedRE.model.Session;
import estimators.numberoOfDocuments.NumberOfDocumentCalculator;

public class WordFrequencyFitter extends AdjustmentOption {

	public WordFrequencyFitter(int K) {
		super(4, K);
		
	}

	@Override
	protected void adapt(DistributedREModel dREModel, Session s,
			MediatorInterface mI) {
		
		ArrayList<QueryDatabase> qdb = s.getQueryDatabases();

		for (QueryDatabase queryDatabase : qdb) {
			
			//Always have something at this point.
			
			ArrayList<Document> docs = (ArrayList<Document>)(queryDatabase.getParameter(Parameter.DOCUMENTS).getValue());
			
			DoubleValuedParameter dvp = (DoubleValuedParameter) queryDatabase.getParameter(Parameter.TOTAL_DOCUMENTS_PROCESSED);
			
			double cant = 0;
			
			if (dvp!=null){
				cant = ((Double)dvp.getValue()).doubleValue();
			}
			
			cant += docs.size();
			
			queryDatabase.addParameter(Parameter.TOTAL_DOCUMENTS_PROCESSED, new DoubleValuedParameter(cant));
			
		}
		
		
	}

}
